package com.onepiece.shipelves.common.enums;


import com.onepiece.shipelves.common.Result;
import com.onepiece.shipelves.common.exception.SystemException;

/**
 * 错误码格式 2xxxyyyy
 * 2表示java
 * xxx 001~099 为系统级别异常分类 100~999表示系统编号
 * yyyy 0001~9999 表示具体异常 由子系统自行定义
 * @author ting
 * @version v1.0
 * @ClassName: SystemExceptionEnum
 * @date 2019-04-26
 */
public enum SystemExceptionEnum implements BaseExceptionEnum{

    //001 系统常见异常
    ILLEGAL_REQUEST_PARAM("20010001","非法参数"),
    UN_KNOW_ERROR("20010002", "系统内部未处理异常"),
    NOT_FIND_AVAILABLE_SERVICE("20010003", "尚未发现可用服务，请稍等"),
    NPE("20010004", "系统内部异常，请联系开发人员处理"),
    RETRYABLE_TIMEOUT_SERVICE("20010005", "微服务超时"),
    PARSE_JSON_ERROR("20010006", "系统内解析JSON报文异常"),
    HTTP_MESSAGE_NOT_READABLE("20010007", "请求报文格式有误"),
    REQUEST_BINDING_ERROR("20010008", "请求参数缺少必要字段"),
    NO_JSON_RESULT_CODE("20010009", "接入HTTP报文内没有code码"),
    HTTP_MESSAGE_EMPTY("20010010", "接入HTTP报文为空"),
    TRANS_HTTP_ERROR("20010011", "接入HTTP请求异常，请联系开发人员处理"),
    SERVICE_STOPPED_NOT_REMOVED("20010012", "已关闭服务尚未从注册中心或副本中移除"),
    MISSING_REQUEST_PARAM("20010013","缺少必要参数"),

    //002 权限控制
    AUTH_ERROR("20020001", "未授权"),
    AUTH_INVALID("20020002", "签名已失效"),
    NO_LOGIN("20020003", "用户未登录"),
    LOGIN_ERROR("20020004", "登录失败"),
    TOKEN_NOT_EXIST("20020005", "无法获取用户Token"),
    AUTH_ERROR_SIGN("20020006", "鉴权失败，客户端签名与服务端不一致"),
    AUTH_ERROR_CODE("20020007", "验证码错误"),
    AUTH_PHONE_CODE_EXIST("20020008", "验证码已发送"),

    //003 db异常
    MYSQL_OPERATING_ERROR("20030001", "mysql操作数据异常"),
    ;
    private String code;

    private String message;

    public final SystemException ex;

    SystemExceptionEnum(String code, String message) {
        this.code = code;
        this.message = message;
        this.ex = new SystemException(code, message);
    }


    @Override
    public Result createResult() {
        Result result = new Result();
        result.setCode(this.code);
        result.setMessage(this.message);
        return result;
    }

    @Override
    public String getExceptionCode() {
        return this.getCode();
    }

    @Override
    public String getExceptionMessage() {
        return this.getMessage();
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }


}

